//
//  BaseTypeTableVeiw.m
//  住房条件帅选器
//
//  Created by MB__Lee on 2018/5/18.
//  Copyright © 2018年 MB__Lee. All rights reserved.
//

#import "BaseTypeTableVeiw.h"
#define  Cell_hight 50
#define  lastCell_higgh 67

@interface BaseTypeTableVeiw()



@end



static NSString *BaseTypeCell_Identi = @"BaseTypeCell";

@implementation BaseTypeTableVeiw

-(void)setSourceMut:(NSMutableArray *)sourceMut{
    _sourceMut = sourceMut;
    
    
    CGRect frame = self.frame;
    CGFloat cacultaHeight = (sourceMut.count -1) * Cell_hight + lastCell_higgh;
    if (cacultaHeight > 0.7 *SCREEN_WIDTH) {
        frame.size.height = 0.7 * SCREEN_HIGHT;
    }else{
        frame.size.height = cacultaHeight;
    }
    self.frame = frame;
    
    [self reloadData];
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    [self selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
}


-(instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style{
    if (self = [super initWithFrame:frame style:style]) {
        [self registerNib:[UINib nibWithNibName:BaseTypeCell_Identi bundle:nil] forCellReuseIdentifier:BaseTypeCell_Identi];
        
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.delegate = self;
        self.dataSource = self;
        
        //设置默认选中
        NSIndexPath *indexpath  =[NSIndexPath indexPathForRow:0 inSection:0];
        [self selectRowAtIndexPath:indexpath animated:YES scrollPosition:UITableViewScrollPositionNone];
        
        
    }
    return self;
}


#pragma mark -- tableview 代理方法、dataSource
-(NSInteger)numberOfSections{
    return  1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  self.sourceMut.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    BaseTypeCell *cell = [tableView dequeueReusableCellWithIdentifier:BaseTypeCell_Identi];
    cell.text = self.sourceMut[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return  cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([self.BaseDelegate respondsToSelector:@selector(BaseTypeTableVeiw:sendSelectedIndexPathString:)]) {
        NSString *indexString = self.sourceMut[indexPath.row];
        
        if (indexPath.row == 0) { //当选中第一行的时候“不限“--传递空给外面
            [self.BaseDelegate BaseTypeTableVeiw:self sendSelectedIndexPathString:@""];
        }else{
             [self.BaseDelegate BaseTypeTableVeiw:self sendSelectedIndexPathString:indexString];
        }
       
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == self.sourceMut.count - 1) {
        return  lastCell_higgh;
    }
    return Cell_hight;
}

-(void)setMinPlaceHolder:(NSString *)minPlaceHolder max:(NSString *)maxPlaceHolder{

}


@end
